//
//  CreateJobReviewSectionView.swift
//  GreenDeal
//
//  Created by Moennig Q on 2023/3/7.
//

import UIKit

class CreateJobReviewSectionView: View {
    var editClosure: (()->Void)?
    let sectionTitleLabel = ContentLabel(R.font.interMedium(size: 13),hexStr: "#292D3299")
    
    //IB init
    required init?(coder aDecoder: NSCoder) {
        super.init(coder:aDecoder)
    }
    init(_  title: String ,haveEditBtnFlag: Bool = true) {
        super.init(frame: CGRect.zero)
        self.sectionTitleLabel.text = title
        self.setUpView(haveEditBtnFlag)
    }
    func setUpView(_ haveEditBtnFlag: Bool = true) {
        self.backgroundColor = UIColor(hexStr: "#F5F5F5")
        self.addSubview(sectionTitleLabel)
        sectionTitleLabel.snp.makeConstraints { make in
            make.top.left.equalTo(16)
            make.height.width.greaterThanOrEqualTo(0)
            make.bottom.equalTo(-6)
        }
        if haveEditBtnFlag {//显示edit btn
            let editLabel = ContentLabel(R.font.interMedium(size: 14),hexStr: "#005D2D")
            editLabel.text = R.string.localizable.edit()
            editLabel.textAlignment = .right
            editLabel.isUserInteractionEnabled = true
            self.addSubview(editLabel)
            editLabel.snp.makeConstraints { make in
                make.centerY.equalTo(sectionTitleLabel)
                make.right.equalTo(-16)
                make.height.equalTo(40)
                make.width.equalTo(50)
            }
            let tapGesture = UITapGestureRecognizer(target: self, action: #selector(editBtnClick))
            editLabel.addGestureRecognizer(tapGesture)
        }
    }
    @objc func editBtnClick(){
        self.editClosure?()
    }

}
